package pe.edu.upc.e41a.javasoft.jsf;

import java.util.logging.Logger;
import java.io.Serializable;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

import org.primefaces.event.CloseEvent;
import org.primefaces.event.FlowEvent;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.roo.addon.jsf.managedbean.RooJsfManagedBean;
import org.springframework.roo.addon.serializable.RooSerializable;

import pe.edu.upc.e41a.javasoft.domain.Publicacion;

@Configurable
@ManagedBean(name = "demopublicacionBean")
@SessionScoped
@RooSerializable
@RooJsfManagedBean(entity = Publicacion.class, beanName = "demopublicacionBean")

public class DemoPublicacionBean implements Serializable{
	
	private static final long serialVersionUID = 1L;
	
		
	private Publicacion publica = new Publicacion();  
	    
	private boolean skip;  
	    
 	private static Logger logger = Logger.getLogger(DemoPublicacionBean.class.getName());  
	 
	 public Publicacion getPublicacion() {  
	    return publica;  
	  }  

	  public void setPublicacion(Publicacion publicacion) {  
	       this.publica = publicacion;  
	  }  
	     
	public void save(ActionEvent actionEvent) {  
	  //Persist user  
	          
	     FacesMessage msg = new FacesMessage("Successful", "Welcome :" + publica.getTitulo());  
	     FacesContext.getCurrentInstance().addMessage(null, msg);  
	}  
	     
	public boolean isSkip() {  
	       return skip;  
	}  

	public void setSkip(boolean skip) {  
	       this.skip = skip;  
	}  
	public String onFlowProcess(FlowEvent event) {  
	      logger.info("Current wizard step:" + event.getOldStep());  
	      logger.info("Next step:" + event.getNewStep());  
	          
	       if(skip) {  
            skip = false;   //reset in case user goes back  
	            return "confirm";  
	        }  
        else {  
            return event.getNewStep();  
	       }  
	}  

	 public void handleClose(CloseEvent event) {  
		      FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Panel Closed", "Closed panel id:'" + event.getComponent().getId() + "'");  
		         
		      addMessage(message);  
		    }  

	 private void addMessage(FacesMessage message) {  
		       FacesContext.getCurrentInstance().addMessage(null, message);  
		  }  

	
}
  

